<?php
defined('BY_JYA') or exit('Access Denied');
/*
	pc端页面组件
*/
if($do=='check'){
	$ids=trim($_RQ['ids']);
	if(!$ids || $ids==';'){
		eci('页面参数错误！','error');
	}
	$ids=explode(';',$ids);
	$pc_blocks=pdo_getall('core_mobile_blocks',array('id'=>$ids),array('id','release'),'id');
	eci($pc_blocks);
}
if($do=='getbuyed'){
	$installed=trim($_RQ['installed']);
	if($installed){
		$installed=explode(';',$installed);
	}
	$trades=pdo_getall('core_trade',array('uniacid'=>$_SESSION['uniacid'],'type'=>7),array('pid'),'pid');
	if(!$trades){
		eci(array());
	}
	$trades=array_keys($trades);
	if($installed){
		$trades=array_diff($trades,$installed);
	}
	if(!$trades){
		eci(array());
	}
	$blocks=pdo_getall('core_mobile_blocks',array('status'=>1,'show'=>1,'id'=>$trades),array('id','title','release'));
	eci($blocks);
}
if($do=='install'){
	$id=trim($_RQ['id']);
	if(!$id){
		eci('请先选择要安装的组件！','error');
	}
	check_buy($id,7);
	//check_install($id,7);
	$block=pdo_get('core_mobile_blocks',array('id'=>$id),array('support','plugin_id','showhtml','edithtml','title','icon','default','release','type','basictype'));
	if(!$block){
		eci('要安装的组件不存在！','error');
	}
	$block['showhtml']=cfc('files')->source_read($block['showhtml']);
	$block['edithtml']=cfc('files')->source_read($block['edithtml']);
	//$local_id=pdo_getcolumn('app_install_id',array('uniacid'=>$_SESSION['uniacid'],'type'=>7),'auto');
	//if(!$local_id){
	//	$local_id=0;
	//}
	//$local_id++;
	//pdo_update('app_install_id',array('auto'=>$local_id),array('uniacid'=>$_SESSION['uniacid'],'type'=>7));
	//$app_install=array('uniacid'=>$_SESSION['uniacid'],'type'=>7,'pid'=>$id,'local_id'=>$local_id);
	//pdo_insert('app_install',$app_install);
	//$block['id']=$local_id;
	eci($block);
}
if($do=='update'){
	$id=trim($_RQ['id']);
	if(!$id){
		eci('请先选择要更新的组件！','error');
	}
	$block=pdo_get('core_mobile_blocks',array('id'=>$id),array('showhtml','edithtml','title','icon','default','release','id','type','basictype','plugin_id','support','type'));
	if(!$block){
		eci('要更新的组件不存在！','error');
	}
	check_buy($block['id'],7);
	$block['showhtml']=cfc('files')->source_read($block['showhtml']);
	$block['edithtml']=cfc('files')->source_read($block['edithtml']);
	unset($block['id']);
	eci($block);
}

eci('无效操作符！','error');